export  const formatTime = (timestamp: string | number) => {
    if (!timestamp) return ''
    const inputDate = new Date(timestamp)
    const nowDate = new Date()
    const isToday = (input: Date, now: Date) =>
        input.getUTCFullYear() === now.getUTCFullYear() &&
        input.getUTCMonth() === now.getUTCMonth() &&
        input.getUTCDate() === now.getUTCDate()
    const isYesterday = (input: Date, now: Date) => {
        const yesterday = new Date(now)
        yesterday.setUTCDate(yesterday.getUTCDate() - 1)
        return (
            input.getUTCFullYear() === yesterday.getUTCFullYear() &&
            input.getUTCMonth() === yesterday.getUTCMonth() &&
            input.getUTCDate() === yesterday.getUTCDate()
        )
    }
    const nowTime = nowDate.getTime()
    const inputTime = inputDate.getTime()
    const diff = nowTime - inputTime
    let timeCategory: 'today' | 'yesterday' | 'week' | 'year' | 'more'
    if (isToday(inputDate, nowDate)) {
        timeCategory = 'today'
    } else if (isYesterday(inputDate, nowDate)) {
        timeCategory = 'yesterday'
    } else if (diff <= 604800000 && diff > 0) {
        timeCategory = 'week'
    } else if (diff <= 31536000000 && diff > 0) {
        timeCategory = 'year'
    } else {
        timeCategory = 'more'
    }
    const timeStr = `${inputDate.getUTCHours().toString().padStart(2, '0')}:${inputDate.getUTCMinutes().toString().padStart(2, '0')}`
    const weekDays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
    switch (timeCategory) {
        case 'today':
            return timeStr
        case 'yesterday':
            return `昨天 ${timeStr}`
        case 'week':
            return `${weekDays[inputDate.getUTCDay()]} ${timeStr}`
        case 'year':
            return `${(inputDate.getUTCMonth() + 1).toString().padStart(2, '0')}-${inputDate.getUTCDate().toString().padStart(2, '0')} ${timeStr}`
        default:
            return `${inputDate.getUTCFullYear()}-${(inputDate.getUTCMonth() + 1).toString().padStart(2, '0')}-${inputDate.getUTCDate().toString().padStart(2, '0')} ${timeStr}`
    }
}